/**
 * Created by Administrator on 2017/3/28.
 */

import {Injectable} from '@angular/core';
import {NavigationBarService} from "../site/service/navigationBar.service";
declare var $: any;
@Injectable()
export class CommonService {

    constructor(private navigationBarService: NavigationBarService) {

    }

    setNavigationBar(str: string) {
        this.navigationBarService.setNavigationBar(str)
    }


    getRequestProUrl() {
        return ""
    }

    getTableOperateBtnCss() {
        return "margin-right: 8px;cursor: pointer;margin-bottom:2px;color:#337ab7"
    }

    showModal(modal: any) {
        $(modal.nativeElement).modal("show")
    }

    hideModal(modal: any) {
        $(modal.nativeElement).modal("hide")
    }

    emptyStr(str: string): boolean {
        if (str == undefined || str == "") {
            return true
        } else {
            return false
        }
    }

    emptyNum(str: number): boolean {
        if (str == undefined) {
            return true
        } else {
            return false
        }
    }

    stringToArray(str: string) {
        let result: any[] = []
        let newStr = str.substring(1, str.length - 1)
        for (let info of  newStr.split(",")) {
            result.push(info.trim())
        }
        return result
    }


    arrayDeepCopy(source:any): any[] {
        let sourceCopy: any[] = Object.assign([],this.objDeepCopy(source))
        return sourceCopy
    }


    objDeepCopy(source:any) {
        var sourceCopy = {};
        for (var item in source) sourceCopy[item] = typeof source[item] === 'object' ? this.objDeepCopy(source[item]) : source[item];
        return sourceCopy;
    }
}